package com.example.demo.control;

import com.example.demo.entity.*;
import com.example.demo.service.As;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ac{
    @Autowired
   As as;
    @GetMapping("getuser/{name}/{pwd}")
    @ResponseBody
    public  result<user> getuser(@PathVariable String name, @PathVariable String pwd){
     result<user> result;
     user u=as.getuser(name, pwd);
     if(u!=null){
      result=new result(200,"ok",u);
     }else {
      result=new result(500,"不存在",null);
     }
        return result;
    }
    @GetMapping("adduser/{name}/{pwd}")
    @ResponseBody
    public  result<Boolean> adduser(@PathVariable String name, @PathVariable String pwd){
     result<Boolean> result;
     boolean f=as.adduser(name, pwd);
     if (f){
      result=new result(200,"ok",true);
     }
     else {
      result=new result(500,"fault",false);
     }
     return result;}
    @GetMapping("getcname/{type}")
    @ResponseBody
    public result<List<String>> getcname(@PathVariable String type){
     result<List<String>> result ;
     List<String> l=as.getcname(type);
     if(!l.isEmpty()){
      result =new result(200,"ok",l);
     }else{
      result=new result(500,"没有数据",null);
     }
     return result;}
    @GetMapping("getc")
    @ResponseBody
    public  result<List<crose>> getc(){
     result<List<crose>> result ;
     List<crose> l=as.getc();
     if(!l.isEmpty()){
      result =new result(200,"ok",l);
     }else{
      result=new result(500,"没有数据",null);
     }
     return result;
    }
    @GetMapping("getclas/{cid}")
    @ResponseBody
    public  result<List<clas>> getclas(@PathVariable int cid){
     result<List<clas>> result ;
     List<clas> l=as.getclas(cid);
     if(!l.isEmpty()){
      result =new result(200,"ok",l);
     }else{
      result=new result(500,"没有数据",null);
     }
     return result;
    }
    @GetMapping("getd/{cid}")
    @ResponseBody
    public result<List<discourage>> getd(@PathVariable int cid){
     result<List<discourage>> result ;
     List<discourage> l=as.getd(cid);
     if(!l.isEmpty()){
      result =new result(200,"ok",l);
     }else{
      result=new result(500,"没有数据",null);
     }
     return result;
    }


}
